package com.le.tester.tip;

/**
 * createTime：2024/3/5 16:52
 * description：AI模型训练数据
 */

import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.le.tester.common.enums.RedisKey;
import com.le.tester.utils.HttpTempUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

public class AModelTester {

    public static String genSign(TreeMap<String, Object> param, String apiKey) {
        param.put("sign", apiKey);
        String sign = SecureUtil.md5(JSON.toJSONString(param)).toUpperCase();
        param.remove("sign");
        return sign;
    }

    public static void main(String[] args) {
        AModelTester tester = new AModelTester();
        tester.getImgToImg();
        //tester.getTask();

    }

    //提交任务
    public void loadModelTask() {
        List<String> photoUrls = new ArrayList<>();

        // photoUrls.add("https://bojuematerial-prudcut-public.oss-cn-guangzhou.aliyuncs.com/%E6%B5%8B%E8%AF%95.jpg_2023071914133169_1689747251564.jpg");
        //photoUrls.add("https://bojuematerial-prudcut-public.oss-cn-guangzhou.aliyuncs.com/%E6%B5%8B%E8%AF%95.jpg_2023071910045940_1689732398057.jpg");

//        photoUrls.add("https://bojuematerial-prudcut-public.oss-cn-guangzhou.aliyuncs.com/2021091014131244_12_1631257736617.jpg");
//        photoUrls.add("https://bojuematerial-prudcut-public.oss-cn-guangzhou.aliyuncs.com/2021091014131244_12_1631257736621.jpg");
//
//        photoUrls.add("https://bojuematerial-prudcut-public.oss-cn-guangzhou.aliyuncs.com/2021091014131244_12_1631257736613.jpg");
//        photoUrls.add("https://bojuematerial-prudcut-public.oss-cn-guangzhou.aliyuncs.com/2021091014131244_12_1631257736630.jpg");

        photoUrls.add("https://bojuematerial-prudcut-public.oss-cn-guangzhou.aliyuncs.com/2021091014131244_12_1631258622709.jpg");
        photoUrls.add("https://bojuematerial-prudcut-public.oss-cn-guangzhou.aliyuncs.com/2021091014131244_12_1631263093187.jpg");


//        List<String> photoUrls = new ArrayList<>() {{
//            add("https://bjy-public-1312487572.cos.ap-shanghai.myqcloud.com/test/retouched_girl/DSC06666.jpg");
//            add("https://bjy-public-1312487572.cos.ap-shanghai.myqcloud.com/test/retouched_girl/DSC06679.jpg");
//            add("https://bjy-public-1312487572.cos.ap-shanghai.myqcloud.com/test/retouched_girl/DSC06683.jpg");
//            add("https://bjy-public-1312487572.cos.ap-shanghai.myqcloud.com/test/retouched_girl/DSC06687.jpg");
//            add("https://bjy-public-1312487572.cos.ap-shanghai.myqcloud.com/test/retouched_girl/DSC06689.jpg");
//            add("https://bjy-public-1312487572.cos.ap-shanghai.myqcloud.com/test/retouched_girl/DSC06698.jpg");
//            add("https://bjy-public-1312487572.cos.ap-shanghai.myqcloud.com/test/retouched_girl/DSC06700.jpg");
//            add("https://bjy-public-1312487572.cos.ap-shanghai.myqcloud.com/test/retouched_girl/DSC06702.jpg");
//            add("https://bjy-public-1312487572.cos.ap-shanghai.myqcloud.com/test/retouched_girl/DSC06755.jpg");
//        }};
        String userTel = "13859949573";
        String thirdNo = "1744991631129849856";
        // 参数必须使用自带排序的TreeMap
        TreeMap<String, Object> param = new TreeMap<>();
        param.put("userTel", userTel);
        param.put("photoUrls", photoUrls);
        param.put("thirdNo", thirdNo);
        String sign = genSign(param, "zxg20240314");
        String merchantId = "3";

        TreeMap<String, String> headerMap = new TreeMap<>();

        headerMap.put("x-merchant-id", merchantId);
        headerMap.put("x-sign", sign);


        JSONObject jsonObject = HttpTempUtils.postFreeParam("https://dev-ai-api.bojueyou.com.cn/api/open/post/user/lora/model",
                JSON.toJSONString(param), headerMap);
        System.out.println(jsonObject);
    }

    //任务结果
    public void getImgToImg() {
        TreeMap<String, Object> param = new TreeMap<>();
        param.put("taskId", 148);

        JSONObject jsonObject = HttpTempUtils.postFreeParam("https://test-ai-api.bojueyou.com.cn/api/open/get/user/img2img", JSON.toJSONString(param), getHeader(param));
        System.out.println(jsonObject.get("data"));
    }

    public TreeMap<String, String> getHeader(TreeMap<String, Object> param) {
        String merchantId = "3";
        String sign = genSign(param, "zxg20240314");

        TreeMap<String, String> headerMap = new TreeMap<>();

        headerMap.put("x-merchant-id", merchantId);
        headerMap.put("x-sign", sign);
        return headerMap;
    }


}
